<?php

# The home location for this file is the sitefront/front-framework project.
# It gets copied to other projects

global $options, $context;

#########################################################################################
# $version     - the version of code we are running (prod, stage, test, uidev, latest, dev, YYYYMMDD)
# $apps_dir    - the file system directory of installed application software (should be absolute, but may be relative)
# $apps_urldir - the URL directory of installed application software         (should be absolute, but may be relative)
#                $version and all of the file and URL paths should be determined strictly from
#                paths in $_SERVER (as well as the symlinks they follow)
#########################################################################################

if (isset($_SERVER['DOCUMENT_ROOT'])) {
    $document_root = $_SERVER['DOCUMENT_ROOT'];
    $document_base = dirname($document_root);
}
else {
    $document_root = '.';
    $document_base = '.';
}

$cwd  = getcwd();
if (isset($_SERVER['SCRIPT_FILENAME'])) {
    $script_filename      = $_SERVER['SCRIPT_FILENAME'];
    #$script_basename      = basename($script_filename);
    #if ($script_basename === 'phpunit') { }
    if (isset($_SERVER['argv'])) {
        $argc = count($_SERVER['argv']);
        $php = $_SERVER['argv'][$argc-1];
        if (! preg_match('/\\.php$/',$php)) {
            $php .= '.php';
        }
        $script_filename_dir  = $cwd;
        $script_filename      = $cwd.'/'.$php;
    }
    else {
        $script_filename_dir  = dirname($script_filename);
    }
}
else {
    error_log('WARNING: script_filename not found from _SERVER[SCRIPT_FILENAME] or argv[0]');
    $script_filename      = '';
    $script_filename_dir  = '.';
}

#########################################################################################
# Adjust $script_name - if FIRST element of the script path is a symlink
#                       (this assumes the symlink is a simple, relative, downward symlink)
#########################################################################################
$matches        = array();
$script_name = (isset($_SERVER['SCRIPT_NAME'])) ? $_SERVER['SCRIPT_NAME'] : '';
if (preg_match('!^/([^/]+)/([^/].*)$!', $script_name, $matches)) {
    $script_name_start = $matches[1];
    $script_name_rest  = $matches[2];
    if (is_link("$document_root/$script_name_start")) {
        $script_name_start = readlink("$document_root/$script_name_start");
        $script_name = "/$script_name_start/$script_name_rest";
    }
}

if ($script_name) {
    $script_name_basename = basename($script_name);
    $script_name_dir      = dirname($script_name);
}
else {
    $script_name_basename = '';
    $script_name_dir      = '';
}

$script_symlink_path      = '';
$script_symlink_dir       = '.';
$script_symlink_basename  = '';
$adj_script_name_dir      = $script_name_dir;
$adj_script_filename_dir  = $script_filename_dir;
#echo "INIT:   adj_script_filename_dir=[$adj_script_filename_dir]<br>\n";
#echo "INIT:   adj_script_name_dir=[$adj_script_name_dir]<br>\n";

#########################################################################################
# Adjust script_name - if LAST element of the script path is a symlink
#                      (this assumes the symlink is a simple, relative, downward symlink)
#########################################################################################
if ($script_name_basename && is_link($script_name_basename)) {
    $script_symlink_path     = readlink($script_name_basename);
    $script_symlink_dir      = dirname($script_symlink_path);
    $script_symlink_basename = basename($script_symlink_path);
    if ($script_symlink_dir && $script_symlink_dir !== '.') {
        chdir($script_symlink_dir);                          # change directory to a symlinked script's directory
        #echo "BEFORE: adj_script_filename_dir=[$adj_script_filename_dir]<br>\n";
        #echo "BEFORE: adj_script_name_dir=[$adj_script_name_dir]<br>\n";
        #echo "BEFORE: script_symlink_dir=[$script_symlink_dir]<br>\n";
        $adj_script_name_dir     = ($adj_script_name_dir     && $adj_script_name_dir     !== '/') ? "$adj_script_name_dir/$script_symlink_dir"     : "/$script_symlink_dir";
        $adj_script_filename_dir = ($adj_script_filename_dir && $adj_script_filename_dir !== '/') ? "$adj_script_filename_dir/$script_symlink_dir" : "/$script_symlink_dir";
        #echo "AFTER:  adj_script_filename_dir=[$adj_script_filename_dir]<br>\n";
        #echo "AFTER:  adj_script_name_dir=[$adj_script_name_dir]<br>\n";
    }
}

#########################################################################################
# Determine the $version, $apps_dir, $apps_urldir
#########################################################################################
$version_urlpath = '/v';
$version         = '';
$real_version    = '';
# executed from a web server
if (preg_match('!^(.*/v)/([^/]+)/!', $adj_script_name_dir, $matches)) {
    $version_urlpath  = $matches[1];
    $version          = $matches[2];
}
# executed from the command line and installed in a daily snapshot release
elseif (preg_match('!/sitefront-([^/]+)/!', $cwd, $matches)) {
    $version = $matches[2];
}
# executed from the command line and installed in dev sandbox
else {
    $version = 'prod';
}
$version_dir      = "$document_root$version_urlpath";
if (is_link("$version_dir/$version")) {
    $real_version = readlink("$version_dir/$version");
}
else if (is_dir("$version_dir/$version")) {
    $real_version = $version;
}

if (is_dir("$version_dir/$version/apps")) {
    $apps_dir    = "$version_dir/$version/apps";
}
elseif (preg_match('!^(.*[\\\\/]apps)[\\\\/]!', $cwd, $matches)) {
    $apps_dir    = $matches[1];
}
elseif (isset($_SERVER['PREFIX'])) {
    $apps_dir    = $_SERVER['PREFIX'].'/apps';
}
else {
    $apps_dir    = '../..';
}

#########################################################################################
# $app_env     - the application environment (prod, test, dev, test-ui, test-api, prod-latest, test-latest, dev-latest, YYYYMMDD)
# $appdata     - file system directory for data (etc, data, log)
# $prefix      - older misnomer for $appdata (they should be the same value)
#                $app_env, $appdata, and $prefix may be guessed at based on the $version and $real_version.
#                However, the values may be overridden in options.ini.
#########################################################################################

$test_mode_reqd  = false;
$appdata         = getenv('APPDATA');   # possibly this is already set in the environment (i.e. Apache ENV config or command line use via phpunit)
if ($appdata) {
    error_log("PREFIX [$appdata] is set in APPDATA environment variable");
}

# web usage as called from the phpunit test driver
if (!$appdata && isset($_COOKIE['appdata']) && $_COOKIE['appdata']) {
    $appdata = $_COOKIE['appdata'];
    error_log("PREFIX [$appdata] is set in the 'appdata' cookie");
    $test_mode_reqd = true;                   # ensure that we are in test_mode. otherwise, this would be insecure.
}

if (isset($appdata) && $appdata) {
    if (file_exists("$appdata/etc/options.ini")) {
        $options_file = "$appdata/etc/options.ini";
    }
}
if (!isset($options_file)) {
    # options.ini might be in the current directory (not usual for production, but maybe for dev and test)
    #error_log("PREFIX : testing options.ini in '.'");
    #if (file_exists('options.ini')) {
    #    $options_file = 'options.ini';
    #    $appdata       = '.';
    #}

    # Accessing an Application for a Virtual Host through a different Virtual Host
    # options.ini might be in a virtual-host (vhost) specific directory
    # $_SERVER['DOCUMENT_ROOT'] = /mnt/id/apache/default/htdocs
    # $_SERVER['SERVER_NAME']   = 85.100.200.173
    # $_SERVER['SCRIPT_NAME']   = /internetdynamics.com/v/dev/apps/sitefront/front-framework/test_request.php
    if (!isset($options_file)) {
        #error_log("PREFIX : checking adj_script_name_dir [$adj_script_name_dir] for '^/domain.com/'");
        if (preg_match('!^/(www/)?([^/]+)\\.(com|net|org|edu|gov)/!', $adj_script_name_dir, $matches)) {
            $vhost                = "$matches[2].$matches[3]";
            $vhost_dir            = dirname($document_base) . '/' . $vhost;
            if (isset($version)) {
                $possible_appdata = $vhost_dir . '/env/' . $version;
                #error_log("PREFIX : testing options.ini in '$possible_appdata'");
                if (file_exists("$possible_appdata/etc/options.ini")) {
                    $options_file = "$possible_appdata/etc/options.ini";
                    $app_env      =  $version;
                    $appdata      =  $possible_appdata;
                }
            }
            if (!isset($options_file)) {
                if     (!isset($version) || !$version)                                        { $secondary_app_env = 'prod'; }
                elseif (preg_match('/^([a-z]+)-/', $version, $matches))                       { $secondary_app_env = $matches[1]; }
                elseif (preg_match('/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/', $version)) { $secondary_app_env = 'test'; }
                else                                                                          { $secondary_app_env = 'dev';  }
                $possible_appdata = $vhost_dir . '/env/' . $secondary_app_env;
                #error_log("PREFIX : testing options.ini in '$possible_appdata'");
                if (file_exists("$possible_appdata/etc/options.ini")) {
                    $options_file = "$possible_appdata/etc/options.ini";
                    $app_env      =  $secondary_app_env;
                    $appdata      =  $possible_appdata;
                }
            }
            if (!isset($options_file)) {
                $possible_appdata = $vhost_dir . '/env/prod';
                #error_log("PREFIX : testing options.ini in '$possible_appdata'");
                if (file_exists("$possible_appdata/etc/options.ini")) {
                    $options_file = "$possible_appdata/etc/options.ini";
                    $app_env      =  'prod';
                    $appdata      =  $possible_appdata;
                }
            }
        }
    }

    # Typical: the $appdata is the directory above the document_root
    # options.ini might be associated with the directory above the document_root
    # $_SERVER['DOCUMENT_ROOT'] = /mnt/id/apache/internetdynamics.com/htdocs
    # $_SERVER['SERVER_NAME']   = www.internetdynamics.com
    # $_SERVER['SCRIPT_NAME']   = /v/dev/apps/sitefront/front-framework/test_request.php
    if (!isset($options_file) && isset($version)) {
        $possible_appdata = $document_base . '/env/' . $version;
        #error_log("PREFIX : testing options.ini in '$possible_appdata'");
        if (file_exists("$possible_appdata/etc/options.ini")) {
            $options_file = "$possible_appdata/etc/options.ini";
            $app_env      =  $version;
            $appdata      =  $possible_appdata;
        }
    }
    if (!isset($options_file)) {
        if     (!isset($version) || !$version)                                        { $secondary_app_env = 'prod'; }
        elseif (preg_match('/^([a-z]+)-/', $version, $matches))                       { $secondary_app_env = $matches[1]; }
        elseif (preg_match('/^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/', $version)) { $secondary_app_env = 'test'; }
        else                                                                          { $secondary_app_env = 'dev';  }
        $possible_appdata = $document_base . '/env/' . $secondary_app_env;
        #error_log("PREFIX : testing options.ini in '$possible_appdata'");
        if (file_exists("$possible_appdata/etc/options.ini")) {
            $options_file = "$possible_appdata/etc/options.ini";
            $app_env      =  $secondary_app_env;
            $appdata      =  $possible_appdata;
        }
    }
    if (!isset($options_file)) {
        $possible_appdata = $document_base . '/env/prod';
        #error_log("PREFIX : testing options.ini in '$possible_appdata'");
        if (file_exists("$possible_appdata/etc/options.ini")) {
            $options_file = "$possible_appdata/etc/options.ini";
            $app_env      =  'prod';
            $appdata      =  $possible_appdata;
        }
    }

    # A workstation (development server). Software installed inside the DOCUMENT_ROOT
    # $_SERVER['DOCUMENT_ROOT'] = /var/www
    # $_SERVER['SERVER_NAME']   = localhost
    # $_SERVER['SCRIPT_NAME']   = /spadkins/apps/sitefront/front-framework/test_request.php
    if (!isset($options_file)) {
        #error_log("PREFIX : checking adj_script_name_dir [$adj_script_name_dir] for '/apps/'");
        $possible_appdata = $apps_dir;
        #error_log("PREFIX : testing options.ini in '$possible_appdata'");
        if (file_exists("$possible_appdata/etc/options.ini")) {
            $options_file = "$possible_appdata/etc/options.ini";
            $appdata      =  $possible_appdata;
        }
    }

    if (!isset($options_file)) {
        if (file_exists('options.ini')) {
            $options_file = 'options.ini';
            $appdata      = '.';
        }
    }
}
if (!isset($app_env)) $app_env = 'prod';

$os = PHP_OS;

if (stristr (PHP_OS, 'WIN') && !stristr (PHP_OS, 'DARWIN')) {
    $os = 'WIN';
    if (!defined('PHP_PATHSEP')) define('PHP_PATHSEP', ";");
    if (!isset($options_file)) {
        if (file_exists('options.ini.win')) {
            $options_file = 'options.ini.win';   # this only happens for right-out-of-the-box installs (for quick startup)
            $appdata = '.';
        }
    }
}
else {
    if (!defined('PHP_PATHSEP')) define('PHP_PATHSEP', ":");
    if (!isset($options_file)) {
        if (file_exists('options.ini.linux')) {
            $options_file = 'options.ini.linux';   # this only happens for right-out-of-the-box installs (for quick startup)
            $appdata = '.';
        }
    }
}

if (!isset($options_file)) {
    error_log("ERROR: options.ini not found.");
    error_log("       (If running from the command line, try setting the APPDATA environment variable");
    error_log("        so that {APPDATA}/etc/options.ini can be found.)");
    error_log("       (For development, it should probably be the 'apps' directory in which you installed 'sitefront'.)");
    exit(-1);
}
if (!isset($appdata)) {
    error_log("ERROR: appdata directory could not be determined");
    exit(-1);
}

#########################################################################################
# finally, we are ready to read the "options.ini" file
#########################################################################################
$options = parse_ini_file($options_file);

#########################################################################################
# put auto-detected values in $options (possibly overriding what's in options.ini)
#########################################################################################
$options['os'] = $os;
$options['options_file'] = $options_file;
if (!isset($options['test_mode'])) $options['test_mode'] = 0;

if ($test_mode_reqd && !$options['test_mode']) {
    error_log("ERROR: must be in test mode (options[test_mode] = 1)");
    exit(-1);
}

if (isset($options['appdata']))     { $appdata = $options['appdata']; }
else                                { $options['appdata'] = $appdata; $options['prefix'] = $appdata; }

if (isset($options['app_env']))     { $app_env = $options['app_env']; }
else                                { $options['app_env'] = $app_env; }

#########################################################################################
# Determine the site_baseurl - based on $_SERVER values
#########################################################################################
# $_SERVER['HTTP_HOST']       = www.internetdynamics.com
# $_SERVER['SERVER_NAME']     = www.internetdynamics.com
# $_SERVER['SERVER_ADDR']     = 10.99.46.98
# $_SERVER['DOCUMENT_ROOT']   = /mnt/id/apache/acoexhibithall.com/htdocs
# $_SERVER['SCRIPT_NAME']     = /v/dev/apps/sitefront/front-framework/test_request.php
# $_SERVER['SCRIPT_FILENAME'] = /mnt/id/apache/acoexhibithall.com/htdocs/v/dev/apps/sitefront/front-framework/test_request.php

if (isset($options['http_host'])) { $http_host = $options['http_host']; }
else {
    $http_host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';  # in testing, this won't be set and we fall back to 'localhost'
    $options['http_host'] = $http_host;
}

if (isset($options['site_baseurl'])) { $baseurl = $options['site_baseurl']; }
else {
    if     (isset($_SERVER['REQUEST_SCHEME']))                      { $scheme = $_SERVER['REQUEST_SCHEME']; }
    elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') { $scheme = 'https'; }
    else                                                            { $scheme = 'http'; }
    if     (isset($_SERVER['SERVER_PORT']))                         { $port   = $_SERVER['SERVER_PORT']; }
    elseif ($scheme === 'https')                                    { $port   = 443; }
    else                                                            { $port   = 80; }
    if     ($scheme === 'https') { $port_modifier = ($port == 443) ? '' : ":$port"; }
    elseif ($scheme === 'http')  { $port_modifier = ($port == 80)  ? '' : ":$port"; }
    else                         { $port_modifier = ''; }
    $baseurl = "$scheme://$http_host$port_modifier";
    $options['site_baseurl'] = $baseurl;
}

if (isset($options['apps_dir']))    { $apps_dir = $options['apps_dir']; }
else                                { $options['apps_dir'] = $apps_dir; }

if (isset($options['apps_urldir'])) { $apps_urldir = $options['apps_urldir']; }
else {
    if ($version) {
        $apps_urldir = "$baseurl$version_urlpath/$version/apps";
    }
    else {
        $apps_urldir = "$baseurl/v/$version/apps";
    }
    $options['apps_urldir'] = $apps_urldir;
}

$options['adj_script_name_dir']     = $adj_script_name_dir;
$options['adj_script_name']         = ($script_symlink_path) ? "$script_name_dir/$script_symlink_path" : $script_name;
$options['adj_script_filename_dir'] = $adj_script_filename_dir;
$options['adj_script_filename']     = ($script_symlink_path) ? "$script_filename_dir/$script_symlink_path" : $script_filename;
$options['script_symlink_dir']      = $script_symlink_dir;

if ($version) {
    $options['version']             = $version;
    $options['real_version']        = $real_version;
    $options['version_dir']         = $version_dir;
    $options['version_urldir']      = "$baseurl$version_urlpath";
}
elseif (isset($options['version'])) {
    $version = $options['version'];
    if (! isset($options['real_version']))   $options['real_version']   = '';
    if (! isset($options['version_dir']))    $options['version_dir']    = $version_dir;
    if (! isset($options['version_urldir'])) $options['version_urldir'] = "$baseurl$version_urlpath";
}
else {
    $options['version'] = 'prod';
    if (! isset($options['real_version']))   $options['real_version']   = '';
    if (! isset($options['version_dir']))    $options['version_dir']    = $version_dir;
    if (! isset($options['version_urldir'])) $options['version_urldir'] = "$baseurl$version_urlpath";
}

$options['global_cookie_domain'] = $http_host;
if (!isset($options['site']) || !isset($options['site_short']) || !isset($options['site6']) || !isset($options['global_cookie_domain'])) {
    $site = $http_host;
    if (preg_match('!([^.]+)\\.(com|net|org|edu|gov)$!', $http_host, $matches)) {
        $options['global_cookie_domain'] = '.'.$matches[1].'.'.$matches[2];
        $options['site']             = $matches[1].'.'.$matches[2];
        $options['site_short']       = $matches[1];
    }
    $options['site6']                = substr($options['site'],0,6);
}

#########################################################################################
# enhance the include path (relative paths are made absolute relative to $apps_dir)
#########################################################################################

$old_include_path = get_include_path();
$abs_include_dirs = array();
if (isset($options['include_path'])) {
    $include_dirs = explode(PHP_PATHSEP, $options['include_path']);
    foreach ($include_dirs as $i => $dir) {
        if (!preg_match('/^(?:\/|\\|\w\:[\\/])/', $dir)) {   # if not an absolute directory path ...
            $dir = "$apps_dir/$dir";                         #     make it relative to $apps_dir
        }
        array_push($abs_include_dirs, $dir);                 #     include it in the list of include paths
    }
}
if (is_dir("$appdata/lib")) {
    array_unshift($abs_include_dirs, "$appdata/lib");
}
if (count($abs_include_dirs) > 0) {
    $abs_include_path = join(PHP_PATHSEP, $abs_include_dirs) . PHP_PATHSEP . $old_include_path;
    set_include_path($abs_include_path);
}
else {
    $abs_include_path = $old_include_path;
}
$options['abs_include_path'] = $abs_include_path;

#########################################################################################
# enhance relative urldir's (relative paths are made absolute relative to $apps_urldir)
#########################################################################################
foreach (array('ext_urldir') as $urldir_option) {
    if (isset($options[$urldir_option])) {
        $urldir = $options[$urldir_option];
        if ($urldir[0] != '/' && !preg_match('/^[a-z]+:/', $urldir)) {
            $options[$urldir_option] = $options['apps_urldir'] . '/' . $urldir;
        }
    }
}

#########################################################################################
# start up the Context
#########################################################################################

if (!isset($options['skip_context']) || !$options['skip_context']) {
    require_once('App.php');
    $context = App::context($options);
}

#########################################################################################
# sample scenarios
#########################################################################################

# PRODUCTION
# Typical: the $appdata is the directory above the document_root
# options.ini might be associated with the directory above the document_root
# $_SERVER['DOCUMENT_ROOT']   = /mnt/id/apache/internetdynamics.com/htdocs
# $_SERVER['SERVER_NAME']     = www.internetdynamics.com
# $_SERVER['SCRIPT_NAME']     = /v/dev/apps/sitefront/front-framework/test_request.php
# $_SERVER['SCRIPT_FILENAME'] = /mnt/id/apache/internetdynamics.com/htdocs/v/dev/apps/sitefront/front-framework/test_request.php
# $document_base              = /mnt/id/apache/internetdynamics.com       (/htdocs stripped from DOCUMENT_ROOT)
# $appdata                    = /mnt/id/apache/internetdynamics.com/prod  (found options.ini in $document_base/prod/etc/options.ini)
# $apps_dir                   = /usr/id/prod/htdocs/apps                  (the realpath() equivalent of the SCRIPT_FILENAME, stripped at "/apps/")
# $_SERVER['SCRIPT_FILENAME'] = /mnt/id/apache/internetdynamics.com/htdocs/v/dev/apps/sitefront/front-framework/test_request.php
# $curr_dir                   = /var/www/spadkins/apps/sitefront/front-framework (as returned by getcwd())

# NON-VHOST PRODUCTION (SHARED SSL or PRE-DNS SETUP)
# Accessing an Application for a Virtual Host through a different Virtual Host
# options.ini might be in a virtual-host (vhost) specific directory
# $_SERVER['DOCUMENT_ROOT']   = /mnt/id/apache/default/htdocs
# $_SERVER['SERVER_NAME']     = 85.100.200.173
# $_SERVER['SCRIPT_NAME']     = /dbfoundry.com/v/dev/apps/sitefront/front-framework/test_request.php
# $_SERVER['SCRIPT_FILENAME'] = /mnt/id/apache/default/htdocs/dbfoundry.com/v/dev/apps/sitefront/front-framework/test_request.php
# $document_base              = /mnt/id/apache/default  (/htdocs stripped from DOCUMENT_ROOT)
# $appdata                    = /var/www/spadkins/apps  (or the realpath() equivalent)
# $apps_dir                   = /var/www/spadkins/apps  (or the realpath() equivalent)
# $curr_dir                   = /var/www/spadkins/apps/sitefront/front-framework (as returned by getcwd())

# WORKSTATION-DEV
# A workstation (development server). Software installed inside the DOCUMENT_ROOT
# $_SERVER['DOCUMENT_ROOT']   = /var/www
# $_SERVER['SERVER_NAME']     = localhost
# $_SERVER['SCRIPT_NAME']     = /spadkins/apps/sitefront/front-framework/test_request.php
# $_SERVER['SCRIPT_FILENAME'] = /var/www/spadkins/apps/sitefront/front-framework/test_request.php
# $document_base              = /var                    (/htdocs stripped from DOCUMENT_ROOT)
# $appdata                    = /var/www/spadkins/apps  (or the realpath() equivalent)
# $apps_dir                   = /var/www/spadkins/apps  (or the realpath() equivalent)
# $curr_dir                   = /var/www/spadkins/apps/sitefront/front-framework (as returned by getcwd())

# COMMAND-LINE (phpunit)
# $_SERVER[APPDATA]=[appdata/test01]
# $_SERVER[USER]=[spadkins]
# $_SERVER[LIBPATH]=[/usr/id/prod/lib:/usr/local/lib:/usr/lib:/lib]
# $_SERVER[PATH]=[/usr/id/prod/bin:/opt/sencha-cmd:/home/spadkins/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:.]
# $_SERVER[PWD]=[/usr/id/prod/apps/sitefront/front-framework-test]
# $_SERVER[HOME]=[/home/spadkins]
# $_SERVER[LOGNAME]=[spadkins]
# $_SERVER[PREFIX]=[/usr/id/prod]
# $_SERVER[_]=[/usr/bin/phpunit]
# $_SERVER[PHP_SELF]=[/usr/bin/phpunit]
# $_SERVER[SCRIPT_NAME]=[/usr/bin/phpunit]
# $_SERVER[SCRIPT_FILENAME]=[/usr/bin/phpunit]
# $_SERVER[PATH_TRANSLATED]=[/usr/bin/phpunit]
# $_SERVER[DOCUMENT_ROOT]=[]
# $_SERVER[REQUEST_TIME_FLOAT]=[1387561690.7878]
# $_SERVER[REQUEST_TIME]=[1387561690]

